package com.etc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.Blog;
import com.etc.service.BlogService;


/**
*	@author: zmf  
*	@date: 2018年11月9日 上午10:00:28 
*/

@Controller
public class BlogController {
	@Autowired
	private BlogService blogService;
	
	/**
	 * ajxa请求
	 * @param blogId
	 * @return
	 */
	@RequestMapping(value="blog/{blogId}",method=RequestMethod.GET)
	@ResponseBody
	public Blog getBlogById(@PathVariable("blogId") int blogId) {
		return blogService.getBlogById(blogId);
	}

	/**
	 * 转发
	 * @param blogId
	 * @param model
	 * @return
	 */
	@RequestMapping(value="bloglist/{blogId}",method=RequestMethod.GET)
	public String getBlog(@PathVariable("blogId") int blogId,Model model) {
		Blog blog=blogService.getBlogById(blogId);
		model.addAttribute("blog", blog);
		return "blog";
	}
}
